% B1, B2 & C1, C2

function [coef, p] = func_coef_of_fields(m, CONSTS)

    [coef_all, p_all] = func_p_m_coef_all(m, CONSTS);
    
    w=1e-4;
    coef_all = w*coef_all;
    
%     [coef, p] = func_p_m_coef_all(m, CONSTS);

    
    right_conditions = check_boundary_conditions_for_modes(m, CONSTS, coef_all, p_all);

    for i = 1:size(right_conditions,2)
        if(right_conditions(i)==1)
            p1(i)=p_all(i);
            coef1(:,i)=coef_all(:,i);
        else
            p1(i)=0;
            coef1(:,i)=[0;0;0;0];
        end
    end
    
    l=0;
    p=0;
    coef=[0;0;0;0];
    for ii=1:size(p1,1)
        if(p1(ii)~=0)
            l=l+1;
            p(l)=p1(ii);
            coef(:,l)=coef1(:,ii);
        end
    end
                
end